/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jmodcog2.map;

import jmodcog2.base.BaseConfig;
import jmodcog2.base.BaseRunner;

/**
 *
 * @author Mitch
 */
public abstract class FeatureMapNet extends BaseRunner {
    
//    int input_size, input_len_x, input_len_y;
//    float[] input;
    
    //
    int num_layers;
    int[] data_layer_index0, data_dim_index0;
    int[] num_data_dims;
    int[] data_map_dims;
    int[] data_feature_dims;
    int[] data_step_dims;
    float[] data;
    //
    int[] node_pos_index0, node_weight_index0, node_index0;
    int[] num_node_dims;
    int[] num_node_weights;
    float[] node_position;
    float[] node_weights;
    float[] node_weight_err;
    float[] node_dist_err;
    //
    int[] current_layer = new int[1];
    int[] current_data_index0 = new int[1];
    //

    FeatureMapNet(FeatureMapConfig config) {
        super(config);
    }
    
    
    int _data_map_dim(int layer, int d) {
        return data_map_dims[data_dim_index0[layer] + d];
    }
    
    void _copy_in(int n) {
        if(n < input_size) {
            data[n] = input[n];
        }
    }
    
    void _calc_weight_err(int layer, int node, int weight) {
        int i = 0;
        i = _weight_index(layer, node, weight);
        node_weight_err[i] = data[current_data_index0[0]] - node_weights[i];
    }
    
    void _calc_dist_err(int layer, int node) {
        int i = 0;
        int W = 0;
        float sum = 0;
        float e = 0;
        i = _weight_index(layer, node, 0);
        W = i + num_node_weights[layer];
        while(i < W) {
            e = node_weight_err[i];
            sum += e * e;
        }
        node_dist_err[_node_index(layer, node)] = sum;
    }
    
    int _weight_index(int layer, int node, int weight) {
        return node_weight_index0[layer] + node * num_node_weights[layer] + weight;
    }
    
    int _node_index(int layer, int node) {
        return node_index0[layer] + node;
    }
}
